/// 编辑活动请求模型
class ActivityEditRequest {
  final int activityId;
  final String? activityTitle;
  final String? activityDetails;
  final String? activityLocation;
  final List<String>? activityImages;
  final List<String>? activityType;
  final List<String>? activityTags;
  final int? activityMaxParticipants;
  final String? activityPublishTime;
  final double? latitude;
  final double? longitude;
  final String? activityStatusMessage;
  final Map<String, dynamic>? extraData;

  ActivityEditRequest({
    required this.activityId,
    this.activityTitle,
    this.activityDetails,
    this.activityLocation,
    this.activityImages,
    this.activityType,
    this.activityTags,
    this.activityMaxParticipants,
    this.activityPublishTime,
    this.latitude,
    this.longitude,
    this.activityStatusMessage,
    this.extraData,
  });

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = {
      'activityId': activityId,
    };

    // 只添加非空字段
    if (activityTitle != null && activityTitle!.isNotEmpty) {
      data['activityTitle'] = activityTitle;
    }
    
    if (activityDetails != null && activityDetails!.isNotEmpty) {
      data['activityDetails'] = activityDetails;
    }
    
    if (activityLocation != null && activityLocation!.isNotEmpty) {
      data['activityLocation'] = activityLocation;
    }
    
    if (activityImages != null && activityImages!.isNotEmpty) {
      data['activityImages'] = activityImages;
    }
    
    if (activityType != null && activityType!.isNotEmpty) {
      data['activityType'] = activityType;
    }
    
    if (activityTags != null && activityTags!.isNotEmpty) {
      data['activityTags'] = activityTags;
    }
    
    if (activityMaxParticipants != null) {
      data['activityMaxParticipants'] = activityMaxParticipants;
    }
    
    if (activityPublishTime != null && activityPublishTime!.isNotEmpty) {
      data['activityPublishTime'] = activityPublishTime;
    }
    
    if (latitude != null) {
      data['latitude'] = latitude;
    }
    
    if (longitude != null) {
      data['longitude'] = longitude;
    }
    
    if (activityStatusMessage != null && activityStatusMessage!.isNotEmpty) {
      data['activityStatusMessage'] = activityStatusMessage;
    }
    
    if (extraData != null && extraData!.isNotEmpty) {
      data['extraData'] = extraData;
    }

    return data;
  }

  factory ActivityEditRequest.fromJson(Map<String, dynamic> json) {
    return ActivityEditRequest(
      activityId: json['activityId'] ?? 0,
      activityTitle: json['activityTitle'],
      activityDetails: json['activityDetails'],
      activityLocation: json['activityLocation'],
      activityImages: json['activityImages'] != null
          ? List<String>.from(json['activityImages'])
          : null,
      activityType: json['activityType'] != null
          ? List<String>.from(json['activityType'])
          : null,
      activityTags: json['activityTags'] != null
          ? List<String>.from(json['activityTags'])
          : null,
      activityMaxParticipants: json['activityMaxParticipants'],
      activityPublishTime: json['activityPublishTime'],
      latitude: json['latitude']?.toDouble(),
      longitude: json['longitude']?.toDouble(),
      activityStatusMessage: json['activityStatusMessage'],
      extraData: json['extraData'],
    );
  }
}
